##description of respondent

dat.s.sample <- c(nrow(des.dat), nrow(des.uo), nrow(des.non.uo))

dat.gender <- c(mean(des.dat$demo1.sex=="male", na.rm=TRUE),
                mean(des.uo$demo1.sex=="male", na.rm=TRUE),
                mean(des.non.uo$demo1.sex=="male", na.rm=TRUE))

dat.academic <- c(mean(des.dat$demo3.educ=="undergrad" | des.dat$demo3.educ=="grad", na.rm=TRUE),
                  mean(des.uo$demo3.educ=="undergrad" | des.uo$demo3.educ=="grad", na.rm=TRUE),
                  mean(des.non.uo$demo3.educ=="undergrad" | des.non.uo$demo3.educ=="grad", na.rm=TRUE))

dat.ethnicity <- c(mean(des.dat$demo1.ethnicity=="sep", na.rm=TRUE),
                   mean(des.uo$demo1.ethnicity=="sep", na.rm=TRUE),
                   mean(des.non.uo$demo1.ethnicity=="sep", na.rm=TRUE))

dat.inc.above <- c(mean(des.dat$demo2.income_qual=="high" | des.dat$demo2.income_qual=="v_high", na.rm=TRUE),
                   mean(des.uo$demo2.income_qual=="high" | des.uo$demo2.income_qual=="v_high", na.rm=TRUE),
                   mean(des.non.uo$demo2.income_qual=="high" | des.non.uo$demo2.income_qual=="v_high", na.rm=TRUE))

dat.inc.below <- c(mean(des.dat$demo2.income_qual=="low" | des.dat$demo2.income_qual=="v_low", na.rm=TRUE),
                   mean(des.uo$demo2.income_qual=="low" | des.uo$demo2.income_qual=="v_low", na.rm=TRUE),
                   mean(des.non.uo$demo2.income_qual=="low" | des.non.uo$demo2.income_qual=="v_low", na.rm=TRUE))

dat.age <- c(mean(des.dat$demo1.age, na.rm=TRUE),
             mean(des.uo$demo1.age, na.rm=TRUE),
             mean(des.non.uo$demo1.age, na.rm=TRUE))

dat.left.right <- c(mean(des.dat$demo2.left_right, na.rm=TRUE),
                    mean(des.uo$demo2.left_right, na.rm=TRUE),
                    mean(des.non.uo$demo2.left_right, na.rm=TRUE))

dat.country <- c(mean(des.dat$demo1.country=="IL", na.rm=TRUE),
                 mean(des.uo$demo1.country=="IL", na.rm=TRUE),
                 mean(des.non.uo$demo1.country=="IL", na.rm=TRUE))

###################
gutman.sample <- nrow(des.dat.g)
#age
gutman.age <- mean(des.dat.g$Q151, na.rm=TRUE)

#rescaling the left-right variable
gut.l_R <- rep(NA, length(des.dat.g))
gut.l_R[which(des.dat.g$Q182==1)] <- 7
gut.l_R[which(des.dat.g$Q182==2)] <- 6
gut.l_R[which(des.dat.g$Q182==3)] <- 5
gut.l_R[which(des.dat.g$Q182==4)] <- 4
gut.l_R[which(des.dat.g$Q182==5)] <- 3
gut.l_R[which(des.dat.g$Q182==6)] <- 2
gut.l_R[which(des.dat.g$Q182==7)] <- 1
gutman.left.right <- mean(gut.l_R, na.rm=TRUE)

#gender
gutman.gender <- table(des.dat.g$Q150)[1] / sum(table(des.dat.g$Q150))

#income
gutman.inc.above <- sum(table(des.dat.g$Q173)[1:2]) / sum(table(des.dat.g$Q173)) #above average
gutman.inc.below <-sum(table(des.dat.g$Q173)[4:5]) / sum(table(des.dat.g$Q173)) #below average

#academic education
gutman.academic <- table(des.dat.g$Q166)[1] / sum(table(des.dat.g$Q166))

#sephardic
gutman.ethnic <- table(des.dat.g$Q162)[2] / sum(table(des.dat.g$Q162))

#born in Israel
gutman.israel <- sum(table(des.dat.g$Q152)[6:11]) / sum(table(des.dat.g$Q162))

gutman.dat <- c(gutman.gender, gutman.academic, gutman.ethnic, gutman.inc.above, gutman.inc.below, gutman.age, gutman.left.right, gutman.israel, gutman.sample)
table.dat <- rbind(dat.gender, dat.academic, dat.ethnicity, dat.inc.above, dat.inc.below, dat.age, dat.left.right, dat.country, dat.s.sample)

table.descriptive <- cbind(table.dat, gutman.dat)
colnames(table.descriptive) = c('full.sample','UO','STR','Gutmann')
rownames(table.descriptive) = c('Male','college.degree','sephardic','income.above.average',
                                'income.below.average','age','ideology','Israel.born','N')

outtable = xtable(table.descriptive)
print(outtable,file = 'output/appendix/Table_A3.tex')